package cn.czk.demo;

import dev.langchain4j.data.message.AiMessage;
import dev.langchain4j.model.StreamingResponseHandler;
import dev.langchain4j.model.openai.OpenAiStreamingChatModel;

public class StreamingDemo {

    public static void main(String[] args) {

        OpenAiStreamingChatModel model = OpenAiStreamingChatModel.builder()
                .apiKey("53e452feb1164ec8a6c9cd9112a37d60.xTOwz9t4NIZuYTYb")
                .modelName("glm-4")
                .baseUrl("https://open.bigmodel.cn/api/paas/v4/")
                .temperature(0.95)
                .build();

        model.generate("今天是几月几号？", new StreamingResponseHandler<AiMessage>() {
            @Override
            public void onNext(String token) {
                System.out.print(token);
            }

            @Override
            public void onError(Throwable throwable) {
                System.out.println(throwable);
            }
        });


    }


}
